package com.msy.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.datasource.DataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * @author Irving
 * @create 2021/7/8
 * @desc 配置 DruidDataSourceFactory,然后在xml中引用
 **/
public class DruidDataSourceFactory implements DataSourceFactory {

    private Properties properties = null;

    @Override
    public void setProperties(Properties properties) {
        this.properties = properties;
    }

    @Override
    public DataSource getDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(this.properties.getProperty("driver"));
        dataSource.setUsername(this.properties.getProperty("username"));
        dataSource.setPassword(this.properties.getProperty("password"));
        dataSource.setUrl(this.properties.getProperty("url"));
        return dataSource;
    }
}
